package cate.game.play.skill.passive.hero;

import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 为我方一速时，攻击附加25%伤害和15%暴击，非一速时，100%额外攻击一个目标，造成原技能的80%伤害
 */
public class 灵溪剑道PH extends PassiveHandler {

	private FightAttr 一速属性;

	private int 概率;

	private int 目标;

	private double 血量调整;

	//一速属性=？？&概率=10000&目标=1&血量调整=-2000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		一速属性 = new FightAttr(args.get("一速属性"));
		概率 = args.getInt("概率", 0);
		目标 = args.getInt("目标", 0);
		血量调整 = args.getWDouble("血量调整", 0d);
	}

	@Override
	public void beforeOwnerMove(MoveCtx move, TimeActionCtx action) {
		int teamOrder = move.getTurn().getTeamOrder();
		if (teamOrder <= 0) {
			return;
		}
		if (move.getTurn().getTeamOrder() == 1) {
			skill.owner.attr.addMoveAttr(一速属性);
		} else {
			if (XT.chance(概率)) {
				move.getSkill().param.addTargetNum(目标);
			}
		}
	}

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		if (action.getTurn().getTeamOrder() <= 1) {
			return;
		}
		if (!action.getSkill().cfg.isEffectType(GDSkill.EffectType.伤害)) {
			return;
		}
		for (Fighter target : action.getExTargets()) {
			effect.getTargetCtx(target.getPid()).addHpChangeRate(血量调整);
		}
	}
}
